#include<bits/stdc++.h>
using namespace std;

bool isPrime(int x)
{
	if(x <= 1)
		return false;
	for(int i = 2;i <= sqrt(x);i++)
		if(x%i == 0)
			return false;
	return true;
}

int getSum(int x)
{
	int sum = 0, t;
	while(x)
	{
		t = x%10;
		if(!isPrime(t))
			return 4;
		sum += t;
		x /= 10;
	}
	return sum;
}

int main()
{
	int cnt = 0;
	for(int i = 2;i <= 1000;i++)
	{
		if(isPrime(getSum(i)))
		{
			cnt++;
			cout<<setw(5)<<i;
			if(cnt == 8)
			{
				cnt = 0;
				cout<<endl;
			}
		}
	}
	return 0;
}

